﻿using System.Collections.Generic;
using System;

namespace Models
{
    /// <summary>
    /// A server that contains
    /// </summary>
    public class Server : ModelBase
    {
        /// <summary>
        /// Create a new server
        /// </summary>
        /// <param name="serverName">The name of the server to query</param>
        /// <param name="serverID">The id of the server provider plug in that this server model uses</param>
        /// <param name="serverConnectiontion">A dictionary containing a list of keyed connection information</param>
        public Server(string serverName, Guid serverID, Dictionary<string, string> serverConnectiontion)
        {
            ServerName = serverName;
            ServerConnection = serverConnectiontion;
            ServerID = serverID;
        }

        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="server">Create a deep copy of the supplied server object</param>
        public Server(Server server)
        {
            ServerName = server.ServerName;
            m_ServerConnection = new Dictionary<string, string>();
            ServerID = new Guid(server.ServerID.ToString());

            // Clone the ServerConnection dictionary
            foreach (KeyValuePair<string, string> item in server.ServerConnection)
            {
                string value = item.Value ?? string.Empty;
                m_ServerConnection.Add(item.Key, value);
            }
        }

        /// <summary>
        /// The name of the server to query
        /// </summary>
        public string ServerName
        {
            get
            {
                return m_ServerName;
            }
            set
            {
                m_ServerName = value;
                OnPropertyChanged("ServerName");
            }
        }

        /// <summary>
        /// Details on how to connect to the server
        /// </summary>
        public Dictionary<string, string> ServerConnection
        {
            get
            {
                return m_ServerConnection;
            }
            set
            {
                m_ServerConnection = value;
                OnPropertyChanged("ServerConnection");
            }
        }

        /// <summary>
        /// The id of the server provider plug in that this server model uses
        /// </summary>
        public Guid ServerID
        {
            get
            {
                return m_ServerID;
            }
            set
            {
                m_ServerID = value;
                OnPropertyChanged("ServerID");
            }
        }

        private string m_ServerName;
        private Dictionary<string, string> m_ServerConnection;
        private Guid m_ServerID = Guid.Empty;
    }
}
